package cn.shujuhai.meeting.controller;


import cn.shujuhai.common.domain.PageRequest;
import cn.shujuhai.common.pluging.data.ResultVo;
import cn.shujuhai.meeting.domain.FrequencyVo;
import cn.shujuhai.meeting.domain.Reservation;
import cn.shujuhai.meeting.service.ReservationService;
import com.github.pagehelper.PageInfo;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * @Author: NiuYaHu
 * @Date: 2025/6/17 10:25
 * @Description:
 **/
@RestController
@RequestMapping("/meeting/reservation")
@RequiredArgsConstructor
public class ReservationController {
    final ReservationService reservationService;

    /**
     * 预约
     *
     * @param reservation 预约对象
     * @return 成功或失败的响应信息
     */
    @PostMapping("/add")
    public ResultVo<?> save(@RequestBody List<Reservation> reservation, @RequestParam Long roomId) {
        return this.reservationService.add(reservation, roomId);
    }

    /**
     * 检查
     *
     * @param frequencyVo 预约对象
     * @return 成功或失败的响应信息
     */
    @PostMapping("/check")
    public ResultVo<Set<FrequencyVo>> check(@RequestBody FrequencyVo frequencyVo, @RequestParam Long roomId) {
        return this.reservationService.check(frequencyVo, roomId);
    }

    /**
     * 删除预约set集合中个别预约
     *
     * @param frequencyVo 预约对象
     * @return 成功或失败的响应信息
     */
    @PostMapping("/remove")
    public ResultVo<Set<FrequencyVo>> removeReservation(@RequestBody FrequencyVo frequencyVo) {
        return this.reservationService.removeReservation(frequencyVo);
    }

    /**
     * 获取部门的会议室
     *
     * @param departmentId 部门Id
     * @return 成功或失败的响应信息
     */
    @GetMapping("/getMeetByDepartment")
    public ResultVo<?> getMeetByDepartment(@RequestParam Long departmentId) {
        return this.reservationService.getMeetByDepartment(departmentId);
    }

    /**
     * 清空自身预约的set集合
     */
    @PostMapping("/clear")
    public ResultVo<?> clearSet() {
        return this.reservationService.clear();
    }

    /**
     * 根据登录用户Id和会议室id获取预约集合
     */
    @GetMapping("/reservationListByUserIdAndRoomId")
    public ResultVo<?> reservationListByUserIdAndRoomId(@RequestParam Long roomId) {
        return this.reservationService.reservationListByUserIdAndRoomId(roomId);
    }

    /**
     * 获取部门的会议室
     */
    @GetMapping("/getMeetByUserId")
    public ResultVo<?> getMeetByUserId() {
        return this.reservationService.getMeetByUserId();
    }

    /**
     * 根据登录用户Id查询预约集合
     */
    @GetMapping("/list")
    public ResultVo<PageInfo<Reservation>> getList(Reservation reservation, @Valid PageRequest pageRequest) {
        return this.reservationService.getList(reservation, pageRequest.getPageNum(), pageRequest.getPageSize());
    }

    /**
     * 根据预约Id删除预约
     */
    @PostMapping("/delete/{reservationId}")
    public ResultVo<?> delete(@PathVariable Long reservationId) {
        return this.reservationService.removeByReservationId(reservationId);
    }

    /**
     * 根据预约Id集合批量删除预约
     */
    @PostMapping("/removeBatch")
    public ResultVo<?> removeBatchReservation(@RequestBody List<Long> reservationIds) {
        return this.reservationService.removeBatchReservation(reservationIds);
    }

    /**
     * 根据预约Id编辑预约人和主题
     */
    @PostMapping("/update")
    public ResultVo<?> update(@RequestParam Long reservationId, @RequestParam String purpose, @RequestParam Long userId) {
        return this.reservationService.edit(reservationId, purpose, userId);
    }

    /**
     * 导出预约管理数据
     */
    @GetMapping("/export")
    public void exportReservation(HttpServletResponse response) throws IOException {
        this.reservationService.exportReservation(response);
    }


}
